package org.example.group5back.service;

import org.example.group5back.entity.PersonEntity;
import org.example.group5back.mapper.PersonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class PersonService {
    @Autowired
    PersonMapper personMapper;

    public List<PersonEntity> finAllPerson(){
        return personMapper.findAllPerson();
    }
    public boolean savePerson(PersonEntity ps){
        System.out.println(ps.getId());
        List<PersonEntity> personEntityList = personMapper.findAllPerson();
        Integer next_ps_id = personEntityList.size() + 1;
        System.out.println(next_ps_id);
        if(ps.getId() > 0){
            return personMapper.updatePerson(ps);
        }else{
            ps.setId(next_ps_id);
            return personMapper.insertPerson(ps);
        }
    }
    public boolean deletePerson(Integer ps_id){
        boolean result = personMapper.deletePerson(ps_id);
        personMapper.updateAfterDelete(ps_id);
        return result;
    }
    public List<PersonEntity> showPageLimit(Integer pageNum,Integer pageSize){
        return personMapper.showPageLimit(pageNum,pageSize);
    }
    public List<PersonEntity>  selectPersonByName(String person_number,String person_name,String degree,String person_position,String telephone){
        if(person_name == null){
            System.out.println("1");
        }
        return personMapper.selectByName(person_number,person_name,degree,person_position,telephone);
    }
}
